package com.fgsort;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import jxl.*;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;

public class ExcelWriteListFile {

	public void ExcelWriteListToFile(List<List<String>> lstFunctionGroupsTable, String sExcelFile) {

		try {
			File exlFile = new File(sExcelFile);
			WritableWorkbook writableWorkbook = Workbook.createWorkbook(exlFile);

			WritableSheet writableSheet = writableWorkbook.createSheet("FG_PLC1", 0);

            for (int column = 0; column < lstFunctionGroupsTable.size(); column++) {
                for (int row = 0; row < lstFunctionGroupsTable.get(column).size(); row++) {
                	//System.out.println(lstFunctionGroupsTable.get(column).get(row));
                	Label label = new Label(column, row, lstFunctionGroupsTable.get(column).get(row));
                	///add the created cells to the sheet
                	writableSheet.addCell(label);
                }
            }
			
			//Write and close the workbook
			writableWorkbook.write();
			writableWorkbook.close();
			
			///open the file after creation
			Desktop.getDesktop().open(new File(sExcelFile));

		} catch (IOException e) {
			e.printStackTrace();
		} catch (RowsExceededException e) {
			e.printStackTrace();
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
}

